package com.example.demo.mapper;

import com.example.demo.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BookNapper {
    @Select("select * from book_info where status !=0 " +
            "order by id desc limit #{offset},#{pageSize}")
    public List<BookInfo> getBookInfo(Integer offset, Integer pageSize);
    @Select("select count(1) from book_info where status!=0")
    public int getBookInfoCount();
    @Update("update book_info set book_name=#{bookName},author=#{author},count=#{count}, price=#{price},publish=#{publish} ,status=#{status} where id=#{id}")
   public int updateBookInfo(BookInfo bookInfo);
    @Select("select * from book_info where id=#{id}")
    public BookInfo getBookInfoById(int id);
    @Insert("insert into book_info (book_name,author,count,price,publish,status) values (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
      public int insertBookInfo(BookInfo bookInfo);
    @Update("update book_info set status=0 where id=#{id}")
    public int deleteBookInfoById(Integer id);
//    @Update({
//            "<script>",
//            "UPDATE your_table",
//            "SET column1 = #{value1}, column2 = #{value2}", // 更新的列和对应的值
//            "WHERE id IN",
//            "<foreach item='item' collection='ids' open='(' separator=',' close=')'>",
//            "#{item}",
//            "</foreach>",
//            "</script>"
//    })
    @Update({"<script>",
              "update book_info",
            "set status=0",
            "where id in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    public int batch(List<Integer> ids);
}
